<template>
  <u-popup
    :show="visible"
    mode="bottom"
    @close="close"
    @touchmove.stop.prevent
    :round="8"
  >
    <view class="pop flex-col" :style="{ '--theme': themeColor }">
      <view class="top flex center">请选择门店</view>
      <scroll-view scroll-y class="list flex1">
        <view
          class="class flex flex-btw"
          v-for="(item, index) in list"
          :key="index"
          @click="chooseClass(item)"
        >
          <view :class="[activeStoreId == item[activeFiled] ? 'active' : '']"
            >{{ item.storeName }}
          </view>
        </view>
      </scroll-view>
    </view>
  </u-popup>
</template>
<script>
import { mapState } from "vuex";

export default {
  data() {
    return {
      showAdd: false,
      storeId: "",
      list: [],
    };
  },
  props: {
    visible: {
      default: false,
    },
    activeStoreId: {
      default: "",
    },
    isShowAll: {
      default: true,
    },
    activeFiled: {
      default: "storeId",
      type: String,
    },
  },
  computed: {
    themeColor({ $theme }) {
      return $theme.themeColor.primary;
    },
    ...mapState("sp-product/index", ["shopList"]),
  },
  watch: {
    shopList() {
      this.fetData();
    },
  },
  mounted() {
    this.fetData();
  },
  methods: {
    chooseClass(row) {
      this.$emit("chooseClass", { storeData: row });
      this.close();
    },
    close() {
      this.$emit("update:visible", false);
    },
    fetData() {
      let { activeFiled, shopList } = this;
      let allPar = { storeName: "全部" };
      allPar[activeFiled] = "";
      this.list = this.isShowAll ? [allPar, ...shopList] : [...shopList];
    },
  },
};
</script>
<style lang='scss' scoped>
.pop {
  height: 66vh;
  .top {
    padding: 30rpx 0 35rpx;
    font-size: 30rpx;
    font-weight: 500;
    color: #131313;
    border-bottom: 1rpx solid #c7c7c7;
  }
  .list {
    padding: 0 40rpx;
    width: calc(100% - 80rpx);
    .class {
      font-size: 30rpx;
      color: #131313;
      font-weight: 500;
      min-height: 50rpx;
      margin-bottom: 15rpx;
      margin-top: 30rpx;
      .active {
        color: var(--theme) !important;
      }
    }
  }
}
</style>